home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
Evaluate
/
ParseExpression.h
< prev
next >
Wrap
Text File
|
1994-05-28
|
3KB
|
111 lines
/****************************************************************************************
*
*
* ParseExpression.c -Math Expression parser
*
* ©1993, Graham Cox.
*
****************************************************************************************/
#include "QueueStack.h"
typedef struct
{
char token; // token code byte
int precedence; // precedence value for operators
char tString[8]; // string matching characters for parsing token
long flags; // reserved for future use
}
tEntry, *tEntryPtr, **tEntryHdl;
typedef struct
{
int nEntries; // number of entries in the table
tEntry tkTable[1]; // table entries
}
tokenTable, *tkTabPtr, **tkTabHdl;
typedef struct
{
extended varValue;
char varName[10];
}
varEntry, *varEntryPtr, **varEntryHdl;
typedef struct
{
int vtSize;
varEntry vtTable[1];
}
varTable, *varTabPtr, **varTabHdl;
typedef struct
{
extended startVal; // initial value
extended incVal; // increment value
char varName[10]; // name of this variable
}
svEntry, *svEntryPtr;
typedef struct
{
int nTraces; // number of traces to plot
int autoColour; // flag- auto colour if TRUE
int svEntries; // number of variables in the table
long reserved; // future expansion - do not use
svEntry svTable[1]; // array of parameters
}
secVarTab, *secVarTabPtr, **secVarTabHdl;
#define tokenTableResType 'TOKN'
#define tokenTableResID 128
/* for binary operators, tokens are just the ASCII code of the symbol. For unary
operators, the following token values are defined */
#define UnaryPlus 0xCF //'O
#define UnaryMinus 0xCE //'N
#define Sine 0xD3 //'S
#define Cosine 0xC3 //'C
#define Tangent 0xD4 //'T
#define Exponent 0xC5 //'E
#define Logarithm 0xCC //'L
#define Arcsin 0xD8 //'X
#define Arccos 0xD9 //'Y
#define Arctan 0xDA //'Z
#define Squareroot 0xD1 //'Q
#define Absolute 0xD2
#define RoundOff 0xD6
#define Random 0xD5
#define SyntaxError 100
#define LRParenError 101
#define IllegalTokErr 102
#define ParseError 103
#define endOfLine 104
#define OutOfMemory 105
#define ItsAllGoneWrong 106
#define NoTokenTable 107
#define numeric 1
#define variable 2
#define exponent 3
#define operator 4
#define binOp 5
#define unaryOp 6
#define ErrorStringListID 130
QSHandle MakeRPNQueue(Str255* inString);
extended** MakeFPObject(extended fpData);
varTabHdl MakeVariableTable(QSHandle rpnQueue);
QSHandle CloneQSStruct(QSHandle src);
extended EvaluateRPN(QSHandle rpnQueue,varTabHdl vTab);